package com.xhj.controller;

import com.xhj.service.OSSService;
import com.xhj.util.ResultEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@Api(value="阿里云文件管理")
@CrossOrigin
@RestController
@RequestMapping("/oss/")
public class OSSController {
    @Autowired
    private OSSService ossService;

    @ApiOperation(value = "文件上传")
    @RequestMapping("upload")
    public ResultEntity uploadFile(@ApiParam(name = "file",value = "文件",required = true)
                                   @RequestParam("file") MultipartFile file){
        String avatarUrl = ossService.uploadFile(file);
        return ResultEntity.successWithData().data("avatar",avatarUrl);
    }
}
